<?php

/**
 * 商品咨询
 */

namespace app\shop\common;

class FaqCommon extends \app\base\common\SiteCommon {


    protected function index() {

        $id = request('get', 'id', 0, 'intval');
        if(empty($id)){
            $this->error404();
        }

        $info = target('shop/Shop')->getInfo($id);
        if(empty($info) || !$info['status']) {
            $this->error404();
        }

        $classInfo = target('shop/ShopClass')->getInfo($info['class_id']);
        if(empty($classInfo)) {
            $this->error404();
        }

        $info = target('shop/Shop')->getInfo($id, $classInfo['model_id']);

        $this->setMeta('商品咨询 - ' . $info['title']);

        $crumb = target('shop/ShopClass')->loadCrumbList($info['class_id']);
        $this->setCrumb($crumb);

        $info['images'] = unserialize($info['images']);

        $this->pageInfo['name'] = '商品咨询';

        $urlParam = [];
        $urlParam['id'] = $id;

        $where = [];
        switch($type) {
            case 1:
                $where['level'] = 2;
                break;
            case 2:
                $where['level'] = 1;
                break;
            case 3:
                $where['level'] = 0;
                break;
        }
        $where['app'] = 'shop';
        $where['has_id'] = $id;
        $pageLimit = 20;

        $model = target('shop/ShopFaq');
        $count = $model->countList($where);
        $pageData = $this->pageData($count, $pageLimit, $urlParam);
        $list = $model->loadList($where, $pageData['limit'], 'time desc');

        $this->assign('pageList', $list);
        $this->assign('page', $pageData['html']);
        $this->assign('info', $info);
        $this->assign('classInfo', $classInfo);

        $this->siteDisplay('shop_faq');
    }


}